package _interview150;

import java.util.HashMap;
import java.util.Map;

/**
 * 383. 赎金信
 */
public class No383 {
    public boolean canConstruct(String ransomNote, String magazine) {
        Map<Character, Integer> map = new HashMap<>();
        for (char c : magazine.toCharArray()) {
            map.put(c, map.getOrDefault(c, 0) + 1);
        }
        for (char c : ransomNote.toCharArray()) {
            if (!map.containsKey(c)) return false;
            else if (map.get(c) == 1) map.remove(c);
            else map.put(c, map.get(c) - 1);
        }
        return true;
    }
}
